package com.ruoyi.common.scheduler;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.ruoyi.common.tools.utils.DateUtils;
import com.ruoyi.stat.employee.service.IEmployeeStatService;
import com.ruoyi.stat.equipment.service.IEquipmentStatService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
@Component
public class StatScheduler {
	private final IEmployeeStatService employeeStatService;
	private final IEquipmentStatService equipmentStatService;

	@Value("${spring.profiles.active}")
	private String env;

	@Scheduled(cron = "0 0/30 7-22 * * ?")
	public void stat() {
		//System.out.println(" --- scheduler : " + env + " , " + DateUtils.getCurrDateTime());
		log.info("start task. env : {}", env);
		if ("prod".equals(env)) {
			String queryTime = DateUtils.getCurrDate();
			int empRow = this.employeeStatService.createStatData(queryTime);
			int eqRow = this.equipmentStatService.createStatData(queryTime);
			log.info(
					"queryTime : {} , employeeStatService.createStatData row : {} , equipmentStatService.createStatData row : {}",
					queryTime, empRow, eqRow);
		}
	}
}
